package com.digua.base.socket.response

import com.digua.base.socket.dispatcher.IResponseDispatcher
import com.digua.base.socket.dispatcher.ResponseDelivery


class TextResponse : Response<String> {
    private var responseText: String? = null

    override fun getResponseData(): String? {
        return responseText
    }

    override fun setResponseData(responseData: String) {
        responseText = responseData
    }

    override fun onResponse(dispatcher: IResponseDispatcher?, delivery: ResponseDelivery?) {
        responseText?.let { dispatcher?.onMessage(it, delivery) }
        release()
    }

    override fun toString() = "[@TextResponse${hashCode()}->responseText:${responseText ?: "null"}]"

    override fun release() {
        ResponseFactory.releaseTextResponse(this)
    }
}